﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;

namespace SPThumbnailExtender.Interne
{
    internal class ThumbnailImage : ThumbnailBase
    {
        public ThumbnailImage(Uri uri)
            : base(uri)
        { }
        public ThumbnailImage(Uri uri, int Width, int Height)
            : base(uri, Width, Height)
        { }
        public override System.Drawing.Bitmap GenerateThumbnail()
        {
            return GenerateThumbnail(0);
        }

        public override System.Drawing.Bitmap GenerateThumbnail(int Page)
        {
            Stream streamFile = this.GetFileStream();
            using (Image bmpFile = Bitmap.FromStream(streamFile))
            {

                Image bmpReturn = Helper.FixedSize(bmpFile, this.Width, this.Height);
                return new Bitmap(bmpReturn);

            }
            
        }

        public override void GenerateThumbnails()
        {
            Bitmap bmp= GenerateThumbnail();
            Helper.DeleteThumbnail(this.FileUri, 0);
            Helper.InsertThumbnail(this.FileUri, 0, bmp);
        }

        public override int GetCount()
        {
            return 1;
        }
    }
}
